﻿/******************************************************************
** 文 件 名: BD_ContractChange_DAL.cs
** Copyright (c) 2010-2012 Honestysoft (GuangZhou) Co.,LTD
** 创 建 人: 此代码由生成器自动生成
** 创建日期: 2012-3-15 19:35:23
** 描    述: 实现公共部分的数据访问封装，提供合同变更情况的数据访问类
** 版    本: 2.0.0.0
** 修改描述:
** 修 改 人:
** 修改日期:
******************************************************************/
using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;
using Honestysoft.BaseObject;
using Honestysoft.Financing.Model;

namespace Honestysoft.Financing.DataAccess
{
	/// <summary>
    /// BD_ContractChange数据访问类
    /// </summary>
    public partial class BD_ContractChange_DAL : BaseDataAccess<BD_ContractChange>
    {
        /// <summary>
        /// 构造函数，使用指定的连接字符串
        /// </summary>
        /// <param name="connectionStringName">连接字符串名称</param>
        public BD_ContractChange_DAL(string connectionStringName)
            : base(connectionStringName)
        {

        }

        public DataTable GetContractChange(string projectCategory, string projectId, string projectName, string contractCategory, string code, string name, string id, int pageSize, int currentPageIndex, out int pageCount, out int recordCount)
        {
            DbParameter pProjectCategory = CreateParameter("ProjectCategory");
            pProjectCategory.DbType = DbType.String;
            pProjectCategory.Value = projectCategory;
            DbParameter pProject = CreateParameter("ProjectID");
            pProject.DbType = DbType.String;
            pProject.Value = projectId;
            DbParameter pProjectName = CreateParameter("Name");
            pProjectName.DbType = DbType.String;
            pProjectName.Value = projectName;
            DbParameter pCategory = CreateParameter("ContractCategory");
            pCategory.DbType = DbType.String;
            pCategory.Value = contractCategory;
            DbParameter pCode = CreateParameter("Code");
            pCode.DbType = DbType.String;
            pCode.Value = code;
            DbParameter pName = CreateParameter("Name");
            pName.DbType = DbType.String;
            pName.Value = name;
            DbParameter pID = CreateParameter("ContractID");
            pID.DbType = DbType.String;
            pID.Value = id;
            string sql = string.Format(@"Select A.*,B.Name ContractName,B.Code ContractCode,C.SortCode ProjectSortCode
                From BD_ContractChange A 
                Inner Join BD_Contract B On A.ContractID=B.ID
                Inner Join BD_Project C On B.ProjectID=C.ID
                Where B.IsInit=1 {0} {1} {2} {3} {4} {5} {6}",
                                                         string.IsNullOrEmpty(contractCategory) ? "" : string.Format(" AND B.ContractCategory={0}", pCategory.ParameterName),
                                                          string.IsNullOrEmpty(code) ? "" : string.Format(" AND B.Code LIKE '%'+{0}+ '%' ", pCode.ParameterName),
                                                          string.IsNullOrEmpty(name) ? "" : string.Format(" AND B.Name LIKE '%'+{0}+ '%' ", pName.ParameterName),
                                                          string.IsNullOrEmpty(projectCategory) ? "" : string.Format(" AND C.ProjectCategory={0}", pProjectCategory.ParameterName),
                                                          string.IsNullOrEmpty(projectId) ? "" : string.Format(" AND B.ProjectID={0}", pProject.ParameterName),
                                                          string.IsNullOrEmpty(projectName) ? "" : string.Format(" And C.Name LIKE '%'+{0}+ '%' ", pProjectName.ParameterName),
                                                          string.IsNullOrEmpty(id) ? "" : string.Format(" And A.ContractID={0}", pID.ParameterName));
            DbCommand command = GetDbCommand(sql);
            if (!string.IsNullOrEmpty(contractCategory)) { command.Parameters.Add(pCategory); }
            if (!string.IsNullOrEmpty(code)) { command.Parameters.Add(pCode); }
            if (!string.IsNullOrEmpty(name)) { command.Parameters.Add(pName); }
            if (!string.IsNullOrEmpty(projectCategory)) { command.Parameters.Add(pProjectCategory); }
            if (!string.IsNullOrEmpty(projectId)) { command.Parameters.Add(pProject); }
            if (!string.IsNullOrEmpty(projectName)) { command.Parameters.Add(pProjectName); }
            if (!string.IsNullOrEmpty(id)) { command.Parameters.Add(pID); }
            return ExecuteDataTable(command, "ProjectSortCode,ContractCode,ChangeDate Desc,CreateTime Desc", pageSize, currentPageIndex, out pageCount, out recordCount);

        }
    }
}
